home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / libreadl.0 / libreadl / info / readline.info-2 < prev    next >
Encoding:
GNU Info File  |  1995-11-29  |  36.5 KB  |  979 lines

  1. This is Info file readline.info, produced by Makeinfo-1.55 from the
  2. input file rlman.texinfo.
  3.  
  4.    This document describes the GNU Readline Library, a utility which
  5. aids in the consistency of user interface across discrete programs that
  6. need to provide a command line interface.
  7.  
  8.    Copyright (C) 1988, 1991 Free Software Foundation, Inc.
  9.  
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice pare
  12. preserved on all copies.
  13.  
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided that
  16. the entire resulting derived work is distributed under the terms of a
  17. permission notice identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that this permission notice may be stated in a
  22. translation approved by the Foundation.
  23.  
  24. 
  25. File: readline.info,  Node: Modifying Text,  Next: Utility Functions,  Prev: Redisplay,  Up: Readline Convenience Functions
  26.  
  27. Modifying Text
  28. --------------
  29.  
  30.  - Function: int rl_insert_text (char *text)
  31.      Insert TEXT into the line at the current cursor position.
  32.  
  33.  - Function: int rl_delete_text (int start, int end)
  34.      Delete the text between START and END in the current line.
  35.  
  36.  - Function: char * rl_copy_text (int start, int end)
  37.      Return a copy of the text between START and END in the current
  38.      line.
  39.  
  40.  - Function: int rl_kill_text (int start, int end)
  41.      Copy the text between START and END in the current line to the
  42.      kill ring, appending or prepending to the last kill if the last
  43.      command was a kill command.  The text is deleted.  If START is
  44.      less than END, the text is appended, otherwise prepended.  If the
  45.      last command was not a kill, a new kill ring slot is used.
  46.  
  47. 
  48. File: readline.info,  Node: Utility Functions,  Prev: Modifying Text,  Up: Readline Convenience Functions
  49.  
  50. Utility Functions
  51. -----------------
  52.  
  53.  - Function: int rl_reset_terminal (char *terminal_name)
  54.      Reinitialize Readline's idea of the terminal settings using
  55.      TERMINAL_NAME as the terminal type (e.g., `vt100').
  56.  
  57.  - Function: int alphabetic (int c)
  58.      Return 1 if C is an alphabetic character.
  59.  
  60.  - Function: int numeric (int c)
  61.      Return 1 if C is a numeric character.
  62.  
  63.  - Function: int ding ()
  64.      Ring the terminal bell, obeying the setting of `bell-style'.
  65.  
  66.    The following are implemented as macros, defined in `chartypes.h'.
  67.  
  68.  - Function: int uppercase_p (int c)
  69.      Return 1 if C is an uppercase alphabetic character.
  70.  
  71.  - Function: int lowercase_p (int c)
  72.      Return 1 if C is a lowercase alphabetic character.
  73.  
  74.  - Function: int digit_p (int c)
  75.      Return 1 if C is a numeric character.
  76.  
  77.  - Function: int to_upper (int c)
  78.      If C is a lowercase alphabetic character, return the corresponding
  79.      uppercase character.
  80.  
  81.  - Function: int to_lower (int c)
  82.      If C is an uppercase alphabetic character, return the corresponding
  83.      lowercase character.
  84.  
  85.  - Function: int digit_value (int c)
  86.      If C is a number, return the value it represents.
  87.  
  88. An Example
  89. ----------
  90.  
  91.    Here is a function which changes lowercase characters to their
  92. uppercase equivalents, and uppercase characters to lowercase.  If this
  93. function was bound to `M-c', then typing `M-c' would change the case of
  94. the character under point.  Typing `M-1 0 M-c' would change the case of
  95. the following 10 characters, leaving the cursor on the last character
  96. changed.
  97.  
  98.      /* Invert the case of the COUNT following characters. */
  99.      int
  100.      invert_case_line (count, key)
  101.           int count, key;
  102.      {
  103.        register int start, end, i;
  104.      
  105.        start = rl_point;
  106.      
  107.        if (rl_point >= rl_end)
  108.          return (0);
  109.      
  110.        if (count < 0)
  111.          {
  112.            direction = -1;
  113.            count = -count;
  114.          }
  115.        else
  116.          direction = 1;
  117.      
  118.        /* Find the end of the range to modify. */
  119.        end = start + (count * direction);
  120.      
  121.        /* Force it to be within range. */
  122.        if (end > rl_end)
  123.          end = rl_end;
  124.        else if (end < 0)
  125.          end = 0;
  126.      
  127.        if (start == end)
  128.          return (0);
  129.      
  130.        if (start > end)
  131.          {
  132.            int temp = start;
  133.            start = end;
  134.            end = temp;
  135.          }
  136.      
  137.        /* Tell readline that we are modifying the line, so it will save
  138.           the undo information. */
  139.        rl_modifying (start, end);
  140.      
  141.        for (i = start; i != end; i++)
  142.          {
  143.            if (uppercase_p (rl_line_buffer[i]))
  144.              rl_line_buffer[i] = to_lower (rl_line_buffer[i]);
  145.            else if (lowercase_p (rl_line_buffer[i]))
  146.              rl_line_buffer[i] = to_upper (rl_line_buffer[i]);
  147.          }
  148.        /* Move point to on top of the last character changed. */
  149.        rl_point = (direction == 1) ? end - 1 : start;
  150.        return (0);
  151.      }
  152.  
  153. 
  154. File: readline.info,  Node: Custom Completers,  Prev: Readline Convenience Functions,  Up: Programming with GNU Readline
  155.  
  156. Custom Completers
  157. =================
  158.  
  159.    Typically, a program that reads commands from the user has a way of
  160. disambiguating commands and data.  If your program is one of these, then
  161. it can provide completion for commands, data, or both.  The following
  162. sections describe how your program and Readline cooperate to provide
  163. this service.
  164.  
  165. * Menu:
  166.  
  167. * How Completing Works::    The logic used to do completion.
  168. * Completion Functions::    Functions provided by Readline.
  169. * Completion Variables::    Variables which control completion.
  170. * A Short Completion Example::    An example of writing completer subroutines.
  171.  
  172. 
  173. File: readline.info,  Node: How Completing Works,  Next: Completion Functions,  Up: Custom Completers
  174.  
  175. How Completing Works
  176. --------------------
  177.  
  178.    In order to complete some text, the full list of possible completions
  179. must be available.  That is, it is not possible to accurately expand a
  180. partial word without knowing all of the possible words which make sense
  181. in that context.  The Readline library provides the user interface to
  182. completion, and two of the most common completion functions:  filename
  183. and username.  For completing other types of text, you must write your
  184. own completion function.  This section describes exactly what such
  185. functions must do, and provides an example.
  186.  
  187.    There are three major functions used to perform completion:
  188.  
  189.   1. The user-interface function `rl_complete ()'.  This function is
  190.      called with the same arguments as other Readline functions
  191.      intended for interactive use:  COUNT and INVOKING_KEY.  It
  192.      isolates the word to be completed and calls `completion_matches
  193.      ()' to generate a list of possible completions.  It then either
  194.      lists the possible completions, inserts the possible completions,
  195.      or actually performs the completion, depending on which behavior
  196.      is desired.
  197.  
  198.   2. The internal function `completion_matches ()' uses your
  199.      "generator" function to generate the list of possible matches, and
  200.      then returns the array of these matches.  You should place the
  201.      address of your generator function in
  202.      `rl_completion_entry_function'.
  203.  
  204.   3. The generator function is called repeatedly from
  205.      `completion_matches ()', returning a string each time.  The
  206.      arguments to the generator function are TEXT and STATE.  TEXT is
  207.      the partial word to be completed.  STATE is zero the first time
  208.      the function is called, allowing the generator to perform any
  209.      necessary initialization, and a positive non-zero integer for each
  210.      subsequent call.  When the generator function returns `(char
  211.      *)NULL' this signals `completion_matches ()' that there are no
  212.      more possibilities left.  Usually the generator function computes
  213.      the list of possible completions when STATE is zero, and returns
  214.      them one at a time on subsequent calls.  Each string the generator
  215.      function returns as a match must be allocated with `malloc()';
  216.      Readline frees the strings when it has finished with them.
  217.  
  218.  
  219.  - Function: int rl_complete (int ignore, int invoking_key)
  220.      Complete the word at or before point.  You have supplied the
  221.      function that does the initial simple matching selection algorithm
  222.      (see `completion_matches ()').  The default is to do filename
  223.      completion.
  224.  
  225.  - Variable: Function * rl_completion_entry_function
  226.      This is a pointer to the generator function for `completion_matches
  227.      ()'.  If the value of `rl_completion_entry_function' is `(Function
  228.      *)NULL' then the default filename generator function,
  229.      `filename_entry_function ()', is used.
  230.  
  231. 
  232. File: readline.info,  Node: Completion Functions,  Next: Completion Variables,  Prev: How Completing Works,  Up: Custom Completers
  233.  
  234. Completion Functions
  235. --------------------
  236.  
  237.    Here is the complete list of callable completion functions present in
  238. Readline.
  239.  
  240.  - Function: int rl_complete_internal (int what_to_do)
  241.      Complete the word at or before point.  WHAT_TO_DO says what to do
  242.      with the completion.  A value of `?' means list the possible
  243.      completions.  `TAB' means do standard completion.  `*' means
  244.      insert all of the possible completions.  `!' means to display all
  245.      of the possible completions, if there is more than one, as well as
  246.      performing partial completion.
  247.  
  248.  - Function: int rl_complete (int ignore, int invoking_key)
  249.      Complete the word at or before point.  You have supplied the
  250.      function that does the initial simple matching selection algorithm
  251.      (see `completion_matches ()' and `rl_completion_entry_function').
  252.      The default is to do filename completion.  This calls
  253.      `rl_complete_internal ()' with an argument depending on
  254.      INVOKING_KEY.
  255.  
  256.  - Function: int rl_possible_completions (int count, int invoking_key))
  257.      List the possible completions.  See description of `rl_complete
  258.      ()'.  This calls `rl_complete_internal ()' with an argument of `?'.
  259.  
  260.  - Function: int rl_insert_completions (int count, int invoking_key))
  261.      Insert the list of possible completions into the line, deleting the
  262.      partially-completed word.  See description of `rl_complete ()'.
  263.      This calls `rl_complete_internal ()' with an argument of `*'.
  264.  
  265.  - Function: char ** completion_matches (char *text, CPFunction
  266.           *entry_func)
  267.      Returns an array of `(char *)' which is a list of completions for
  268.      TEXT.  If there are no completions, returns `(char **)NULL'.  The
  269.      first entry in the returned array is the substitution for TEXT.
  270.      The remaining entries are the possible completions.  The array is
  271.      terminated with a `NULL' pointer.
  272.  
  273.      ENTRY_FUNC is a function of two args, and returns a `(char *)'.
  274.      The first argument is TEXT.  The second is a state argument; it is
  275.      zero on the first call, and non-zero on subsequent calls.
  276.      eNTRY_FUNC returns a `NULL'  pointer to the caller when there are
  277.      no more matches.
  278.  
  279.  - Function: char * filename_completion_function (char *text, int state)
  280.      A generator function for filename completion in the general case.
  281.      Note that completion in Bash is a little different because of all
  282.      the pathnames that must be followed when looking up completions
  283.      for a command.  The Bash source is a useful reference for writing
  284.      custom completion functions.
  285.  
  286.  - Function: char * username_completion_function (char *text, int state)
  287.      A completion generator for usernames.  TEXT contains a partial
  288.      username preceded by a random character (usually `~').  As with all
  289.      completion generators, STATE is zero on the first call and non-zero
  290.      for subsequent calls.
  291.  
  292. 
  293. File: readline.info,  Node: Completion Variables,  Next: A Short Completion Example,  Prev: Completion Functions,  Up: Custom Completers
  294.  
  295. Completion Variables
  296. --------------------
  297.  
  298.  - Variable: Function * rl_completion_entry_function
  299.      A pointer to the generator function for `completion_matches ()'.
  300.      `NULL' means to use `filename_entry_function ()', the default
  301.      filename completer.
  302.  
  303.  - Variable: CPPFunction * rl_attempted_completion_function
  304.      A pointer to an alternative function to create matches.  The
  305.      function is called with TEXT, START, and END.  START and END are
  306.      indices in `rl_line_buffer' saying what the boundaries of TEXT
  307.      are.  If this function exists and returns `NULL', or if this
  308.      variable is set to `NULL', then `rl_complete ()' will call the
  309.      value of `rl_completion_entry_function' to generate matches,
  310.      otherwise the array of strings returned will be used.
  311.  
  312.  - Variable: int rl_completion_query_items
  313.      Up to this many items will be displayed in response to a
  314.      possible-completions call.  After that, we ask the user if she is
  315.      sure she wants to see them all.  The default value is 100.
  316.  
  317.  - Variable: char * rl_basic_word_break_characters
  318.      The basic list of characters that signal a break between words for
  319.      the completer routine.  The default value of this variable is the
  320.      characters which break words for completion in Bash, i.e., `"
  321.      \t\n\"\\'`@$><=;|&{("'.
  322.  
  323.  - Variable: char * rl_completer_word_break_characters
  324.      The list of characters that signal a break between words for
  325.      `rl_complete_internal ()'.  The default list is the value of
  326.      `rl_basic_word_break_characters'.
  327.  
  328.  - Variable: char * rl_special_prefixes
  329.      The list of characters that are word break characters, but should
  330.      be left in TEXT when it is passed to the completion function.
  331.      Programs can use this to help determine what kind of completing to
  332.      do.  For instance, Bash sets this variable to "$@" so that it can
  333.      complete shell variables and hostnames.
  334.  
  335.  - Variable: int rl_ignore_completion_duplicates
  336.      If non-zero, then disallow duplicates in the matches.  Default is
  337.      1.
  338.  
  339.  - Variable: int rl_filename_completion_desired
  340.      Non-zero means that the results of the matches are to be treated as
  341.      filenames.  This is *always* zero on entry, and can only be changed
  342.      within a completion entry generator function.  If it is set to a
  343.      non-zero value, directory names have a slash appended and Readline
  344.      attempts to quote completed filenames if they contain any embedded
  345.      word break characters.
  346.  
  347.  - Variable: int rl_filename_quoting_desired
  348.      Non-zero means that the results of the matches are to be quoted
  349.      using double quotes (or an application-specific quoting mechanism)
  350.      if the completed filename contains any characters in
  351.      `rl_completer_word_break_chars'.  This is *always* non-zero on
  352.      entry, and can only be changed within a completion entry generator
  353.      function.
  354.  
  355.  - Variable: Function * rl_ignore_some_completions_function
  356.      This function, if defined, is called by the completer when real
  357.      filename completion is done, after all the matching names have
  358.      been generated.  It is passed a `NULL' terminated array of matches.
  359.      The first element (`matches[0]') is the maximal substring common
  360.      to all matches. This function can re-arrange the list of matches
  361.      as required, but each element deleted from the array must be freed.
  362.  
  363.  - Variable: char * rl_completer_quote_characters
  364.      List of characters which can be used to quote a substring of the
  365.      line.  Completion occurs on the entire substring, and within the
  366.      substring `rl_completer_word_break_characters' are treated as any
  367.      other character, unless they also appear within this list.
  368.  
  369. 
  370. File: readline.info,  Node: A Short Completion Example,  Prev: Completion Variables,  Up: Custom Completers
  371.  
  372. A Short Completion Example
  373. --------------------------
  374.  
  375.    Here is a small application demonstrating the use of the GNU Readline
  376. library.  It is called `fileman', and the source code resides in
  377. `examples/fileman.c'.  This sample application provides completion of
  378. command names, line editing features, and access to the history list.
  379.  
  380.      /* fileman.c -- A tiny application which demonstrates how to use the
  381.         GNU Readline library.  This application interactively allows users
  382.         to manipulate files and their modes. */
  383.      
  384.      #include <stdio.h>
  385.      #include <sys/types.h>
  386.      #include <sys/file.h>
  387.      #include <sys/stat.h>
  388.      #include <sys/errno.h>
  389.      
  390.      #include <readline/readline.h>
  391.      #include <readline/history.h>
  392.      
  393.      extern char *getwd ();
  394.      extern char *xmalloc ();
  395.      
  396.      /* The names of functions that actually do the manipulation. */
  397.      int com_list (), com_view (), com_rename (), com_stat (), com_pwd ();
  398.      int com_delete (), com_help (), com_cd (), com_quit ();
  399.      
  400.      /* A structure which contains information on the commands this program
  401.         can understand. */
  402.      
  403.      typedef struct {
  404.        char *name;            /* User printable name of the function. */
  405.        Function *func;        /* Function to call to do the job. */
  406.        char *doc;            /* Documentation for this function.  */
  407.      } COMMAND;
  408.      
  409.      COMMAND commands[] = {
  410.        { "cd", com_cd, "Change to directory DIR" },
  411.        { "delete", com_delete, "Delete FILE" },
  412.        { "help", com_help, "Display this text" },
  413.        { "?", com_help, "Synonym for `help'" },
  414.        { "list", com_list, "List files in DIR" },
  415.        { "ls", com_list, "Synonym for `list'" },
  416.        { "pwd", com_pwd, "Print the current working directory" },
  417.        { "quit", com_quit, "Quit using Fileman" },
  418.        { "rename", com_rename, "Rename FILE to NEWNAME" },
  419.        { "stat", com_stat, "Print out statistics on FILE" },
  420.        { "view", com_view, "View the contents of FILE" },
  421.        { (char *)NULL, (Function *)NULL, (char *)NULL }
  422.      };
  423.      
  424.      /* Forward declarations. */
  425.      char *stripwhite ();
  426.      COMMAND *find_command ();
  427.      
  428.      /* The name of this program, as taken from argv[0]. */
  429.      char *progname;
  430.      
  431.      /* When non-zero, this global means the user is done using this program. */
  432.      int done;
  433.      
  434.      char *
  435.      dupstr (s)
  436.           int s;
  437.      {
  438.        char *r;
  439.      
  440.        r = xmalloc (strlen (s) + 1);
  441.        strcpy (r, s);
  442.        return (r);
  443.      }
  444.      
  445.      main (argc, argv)
  446.           int argc;
  447.           char **argv;
  448.      {
  449.        char *line, *s;
  450.      
  451.        progname = argv[0];
  452.      
  453.        initialize_readline ();    /* Bind our completer. */
  454.      
  455.        /* Loop reading and executing lines until the user quits. */
  456.        for ( ; done == 0; )
  457.          {
  458.            line = readline ("FileMan: ");
  459.      
  460.            if (!line)
  461.              break;
  462.      
  463.            /* Remove leading and trailing whitespace from the line.
  464.               Then, if there is anything left, add it to the history list
  465.               and execute it. */
  466.            s = stripwhite (line);
  467.      
  468.            if (*s)
  469.              {
  470.                add_history (s);
  471.                execute_line (s);
  472.              }
  473.      
  474.            free (line);
  475.          }
  476.        exit (0);
  477.      }
  478.      
  479.      /* Execute a command line. */
  480.      int
  481.      execute_line (line)
  482.           char *line;
  483.      {
  484.        register int i;
  485.        COMMAND *command;
  486.        char *word;
  487.      
  488.        /* Isolate the command word. */
  489.        i = 0;
  490.        while (line[i] && whitespace (line[i]))
  491.          i++;
  492.        word = line + i;
  493.      
  494.        while (line[i] && !whitespace (line[i]))
  495.          i++;
  496.      
  497.        if (line[i])
  498.          line[i++] = '\0';
  499.      
  500.        command = find_command (word);
  501.      
  502.        if (!command)
  503.          {
  504.            fprintf (stderr, "%s: No such command for FileMan.\n", word);
  505.            return (-1);
  506.          }
  507.      
  508.        /* Get argument to command, if any. */
  509.        while (whitespace (line[i]))
  510.          i++;
  511.      
  512.        word = line + i;
  513.      
  514.        /* Call the function. */
  515.        return ((*(command->func)) (word));
  516.      }
  517.      
  518.      /* Look up NAME as the name of a command, and return a pointer to that
  519.         command.  Return a NULL pointer if NAME isn't a command name. */
  520.      COMMAND *
  521.      find_command (name)
  522.           char *name;
  523.      {
  524.        register int i;
  525.      
  526.        for (i = 0; commands[i].name; i++)
  527.          if (strcmp (name, commands[i].name) == 0)
  528.            return (&commands[i]);
  529.      
  530.        return ((COMMAND *)NULL);
  531.      }
  532.      
  533.      /* Strip whitespace from the start and end of STRING.  Return a pointer
  534.         into STRING. */
  535.      char *
  536.      stripwhite (string)
  537.           char *string;
  538.      {
  539.        register char *s, *t;
  540.      
  541.        for (s = string; whitespace (*s); s++)
  542.          ;
  543.      
  544.        if (*s == 0)
  545.          return (s);
  546.      
  547.        t = s + strlen (s) - 1;
  548.        while (t > s && whitespace (*t))
  549.          t--;
  550.        *++t = '\0';
  551.      
  552.        return s;
  553.      }
  554.      
  555.      /* **************************************************************** */
  556.      /*                                                                  */
  557.      /*                  Interface to Readline Completion                */
  558.      /*                                                                  */
  559.      /* **************************************************************** */
  560.      
  561.      char *command_generator ();
  562.      char **fileman_completion ();
  563.      
  564.      /* Tell the GNU Readline library how to complete.  We want to try to complete
  565.         on command names if this is the first word in the line, or on filenames
  566.         if not. */
  567.      initialize_readline ()
  568.      {
  569.        /* Allow conditional parsing of the ~/.inputrc file. */
  570.        rl_readline_name = "FileMan";
  571.      
  572.        /* Tell the completer that we want a crack first. */
  573.        rl_attempted_completion_function = (CPPFunction *)fileman_completion;
  574.      }
  575.      
  576.      /* Attempt to complete on the contents of TEXT.  START and END show the
  577.         region of TEXT that contains the word to complete.  We can use the
  578.         entire line in case we want to do some simple parsing.  Return the
  579.         array of matches, or NULL if there aren't any. */
  580.      char **
  581.      fileman_completion (text, start, end)
  582.           char *text;
  583.           int start, end;
  584.      {
  585.        char **matches;
  586.      
  587.        matches = (char **)NULL;
  588.      
  589.        /* If this word is at the start of the line, then it is a command
  590.           to complete.  Otherwise it is the name of a file in the current
  591.           directory. */
  592.        if (start == 0)
  593.          matches = completion_matches (text, command_generator);
  594.      
  595.        return (matches);
  596.      }
  597.      
  598.      /* Generator function for command completion.  STATE lets us know whether
  599.         to start from scratch; without any state (i.e. STATE == 0), then we
  600.         start at the top of the list. */
  601.      char *
  602.      command_generator (text, state)
  603.           char *text;
  604.           int state;
  605.      {
  606.        static int list_index, len;
  607.        char *name;
  608.      
  609.        /* If this is a new word to complete, initialize now.  This includes
  610.           saving the length of TEXT for efficiency, and initializing the index
  611.           variable to 0. */
  612.        if (!state)
  613.          {
  614.            list_index = 0;
  615.            len = strlen (text);
  616.          }
  617.      
  618.        /* Return the next name which partially matches from the command list. */
  619.        while (name = commands[list_index].name)
  620.          {
  621.            list_index++;
  622.      
  623.            if (strncmp (name, text, len) == 0)
  624.              return (dupstr(name));
  625.          }
  626.      
  627.        /* If no names matched, then return NULL. */
  628.        return ((char *)NULL);
  629.      }
  630.      
  631.      /* **************************************************************** */
  632.      /*                                                                  */
  633.      /*                       FileMan Commands                           */
  634.      /*                                                                  */
  635.      /* **************************************************************** */
  636.      
  637.      /* String to pass to system ().  This is for the LIST, VIEW and RENAME
  638.         commands. */
  639.      static char syscom[1024];
  640.      
  641.      /* List the file(s) named in arg. */
  642.      com_list (arg)
  643.           char *arg;
  644.      {
  645.        if (!arg)
  646.          arg = "";
  647.      
  648.        sprintf (syscom, "ls -FClg %s", arg);
  649.        return (system (syscom));
  650.      }
  651.      
  652.      com_view (arg)
  653.           char *arg;
  654.      {
  655.        if (!valid_argument ("view", arg))
  656.          return 1;
  657.      
  658.        sprintf (syscom, "more %s", arg);
  659.        return (system (syscom));
  660.      }
  661.      
  662.      com_rename (arg)
  663.           char *arg;
  664.      {
  665.        too_dangerous ("rename");
  666.        return (1);
  667.      }
  668.      
  669.      com_stat (arg)
  670.           char *arg;
  671.      {
  672.        struct stat finfo;
  673.      
  674.        if (!valid_argument ("stat", arg))
  675.          return (1);
  676.      
  677.        if (stat (arg, &finfo) == -1)
  678.          {
  679.            perror (arg);
  680.            return (1);
  681.          }
  682.      
  683.        printf ("Statistics for `%s':\n", arg);
  684.      
  685.        printf ("%s has %d link%s, and is %d byte%s in length.\n", arg,
  686.                finfo.st_nlink,
  687.                (finfo.st_nlink == 1) ? "" : "s",
  688.                finfo.st_size,
  689.                (finfo.st_size == 1) ? "" : "s");
  690.        printf ("Inode Last Change at: %s", ctime (&finfo.st_ctime));
  691.        printf ("      Last access at: %s", ctime (&finfo.st_atime));
  692.        printf ("    Last modified at: %s", ctime (&finfo.st_mtime));
  693.        return (0);
  694.      }
  695.      
  696.      com_delete (arg)
  697.           char *arg;
  698.      {
  699.        too_dangerous ("delete");
  700.        return (1);
  701.      }
  702.      
  703.      /* Print out help for ARG, or for all of the commands if ARG is
  704.         not present. */
  705.      com_help (arg)
  706.           char *arg;
  707.      {
  708.        register int i;
  709.        int printed = 0;
  710.      
  711.        for (i = 0; commands[i].name; i++)
  712.          {
  713.            if (!*arg || (strcmp (arg, commands[i].name) == 0))
  714.              {
  715.                printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc);
  716.                printed++;
  717.              }
  718.          }
  719.      
  720.        if (!printed)
  721.          {
  722.            printf ("No commands match `%s'.  Possibilties are:\n", arg);
  723.      
  724.            for (i = 0; commands[i].name; i++)
  725.              {
  726.                /* Print in six columns. */
  727.                if (printed == 6)
  728.                  {
  729.                    printed = 0;
  730.                    printf ("\n");
  731.                  }
  732.      
  733.                printf ("%s\t", commands[i].name);
  734.                printed++;
  735.              }
  736.      
  737.            if (printed)
  738.              printf ("\n");
  739.          }
  740.        return (0);
  741.      }
  742.      
  743.      /* Change to the directory ARG. */
  744.      com_cd (arg)
  745.           char *arg;
  746.      {
  747.        if (chdir (arg) == -1)
  748.          {
  749.            perror (arg);
  750.            return 1;
  751.          }
  752.      
  753.        com_pwd ("");
  754.        return (0);
  755.      }
  756.      
  757.      /* Print out the current working directory. */
  758.      com_pwd (ignore)
  759.           char *ignore;
  760.      {
  761.        char dir[1024], *s;
  762.      
  763.        s = getwd (dir);
  764.        if (s == 0)
  765.          {
  766.            printf ("Error getting pwd: %s\n", dir);
  767.            return 1;
  768.          }
  769.      
  770.        printf ("Current directory is %s\n", dir);
  771.        return 0;
  772.      }
  773.      
  774.      /* The user wishes to quit using this program.  Just set DONE non-zero. */
  775.      com_quit (arg)
  776.           char *arg;
  777.      {
  778.        done = 1;
  779.        return (0);
  780.      }
  781.      
  782.      /* Function which tells you that you can't do this. */
  783.      too_dangerous (caller)
  784.           char *caller;
  785.      {
  786.        fprintf (stderr,
  787.                 "%s: Too dangerous for me to distribute.  Write it yourself.\n",
  788.                 caller);
  789.      }
  790.      
  791.      /* Return non-zero if ARG is a valid argument for CALLER, else print
  792.         an error message and return zero. */
  793.      int
  794.      valid_argument (caller, arg)
  795.           char *caller, *arg;
  796.      {
  797.        if (!arg || !*arg)
  798.          {
  799.            fprintf (stderr, "%s: Argument required.\n", caller);
  800.            return (0);
  801.          }
  802.      
  803.        return (1);
  804.      }
  805.  
  806. 
  807. File: readline.info,  Node: Concept Index,  Next: Function and Variable Index,  Prev: Programming with GNU Readline,  Up: Top
  808.  
  809. Concept Index
  810. *************
  811.  
  812. * Menu:
  813.  
  814. * interaction, readline:                Readline Interaction.
  815. * Kill ring:                            Readline Killing Commands.
  816. * Killing text:                         Readline Killing Commands.
  817. * readline, function:                   Basic Behavior.
  818. * Yanking text:                         Readline Killing Commands.
  819.  
  820. 
  821. File: readline.info,  Node: Function and Variable Index,  Prev: Concept Index,  Up: Top
  822.  
  823. Function and Variable Index
  824. ***************************
  825.  
  826. * Menu:
  827.  
  828. * $else:                                Conditional Init Constructs.
  829. * $endif:                               Conditional Init Constructs.
  830. * $if:                                  Conditional Init Constructs.
  831. * abort (C-g):                          Miscellaneous Commands.
  832. * accept-line (Newline, Return):        Commands For History.
  833. * alphabetic:                           Utility Functions.
  834. * backward-char (C-b):                  Commands For Moving.
  835. * backward-delete-char (Rubout):        Commands For Text.
  836. * backward-kill-line (C-x Rubout):      Commands For Killing.
  837. * backward-kill-word (M-DEL):           Commands For Killing.
  838. * backward-word (M-b):                  Commands For Moving.
  839. * beginning-of-history (M-<):           Commands For History.
  840. * beginning-of-line (C-a):              Commands For Moving.
  841. * bell-style:                           Readline Init Syntax.
  842. * call-last-kbd-macro (C-x e):          Keyboard Macros.
  843. * capitalize-word (M-c):                Commands For Text.
  844. * clear-screen (C-l):                   Commands For Moving.
  845. * comment-begin:                        Readline Init Syntax.
  846. * complete (TAB):                       Commands For Completion.
  847. * completion-query-items:               Readline Init Syntax.
  848. * completion_matches:                   Completion Functions.
  849. * convert-meta:                         Readline Init Syntax.
  850. * delete-char (C-d):                    Commands For Text.
  851. * delete-horizontal-space ():           Commands For Killing.
  852. * digit-argument (M-0, M-1, ... M-):    Numeric Arguments.
  853. * digit_p:                              Utility Functions.
  854. * digit_value:                          Utility Functions.
  855. * ding:                                 Utility Functions.
  856. * do-uppercase-version (M-a, M-b, ...): Miscellaneous Commands.
  857. * downcase-word (M-l):                  Commands For Text.
  858. * dump-functions ():                    Miscellaneous Commands.
  859. * editing-mode:                         Readline Init Syntax.
  860. * end-kbd-macro (C-x )):                Keyboard Macros.
  861. * end-of-history (M->):                 Commands For History.
  862. * end-of-line (C-e):                    Commands For Moving.
  863. * expand-tilde:                         Readline Init Syntax.
  864. * filename_completion_function:         Completion Functions.
  865. * forward-char (C-f):                   Commands For Moving.
  866. * forward-search-history (C-s):         Commands For History.
  867. * forward-word (M-f):                   Commands For Moving.
  868. * free_undo_list:                       Allowing Undoing.
  869. * history-search-backward ():           Commands For History.
  870. * history-search-forward ():            Commands For History.
  871. * horizontal-scroll-mode:               Readline Init Syntax.
  872. * insert-completions ():                Commands For Completion.
  873. * keymap:                               Readline Init Syntax.
  874. * kill-line (C-k):                      Commands For Killing.
  875. * kill-whole-line ():                   Commands For Killing.
  876. * kill-word (M-d):                      Commands For Killing.
  877. * lowercase_p:                          Utility Functions.
  878. * mark-modified-lines:                  Readline Init Syntax.
  879. * meta-flag:                            Readline Init Syntax.
  880. * next-history (C-n):                   Commands For History.
  881. * non-incremental-forward-search-history (M-n): Commands For History.
  882. * non-incremental-reverse-search-history (M-p): Commands For History.
  883. * numeric:                              Utility Functions.
  884. * output-meta:                          Readline Init Syntax.
  885. * possible-completions (M-?):           Commands For Completion.
  886. * prefix-meta (ESC):                    Miscellaneous Commands.
  887. * previous-history (C-p):               Commands For History.
  888. * quoted-insert (C-q, C-v):             Commands For Text.
  889. * re-read-init-file (C-x C-r):          Miscellaneous Commands.
  890. * readline:                             Basic Behavior.
  891. * redraw-current-line ():               Commands For Moving.
  892. * reverse-search-history (C-r):         Commands For History.
  893. * revert-line (M-r):                    Miscellaneous Commands.
  894. * rl_add_defun:                         Function Naming.
  895. * rl_add_undo:                          Allowing Undoing.
  896. * rl_attempted_completion_function:     Completion Variables.
  897. * rl_basic_word_break_characters:       Completion Variables.
  898. * rl_begin_undo_group:                  Allowing Undoing.
  899. * rl_bind_key:                          Binding Keys.
  900. * rl_bind_key_in_map:                   Binding Keys.
  901. * rl_clear_message:                     Redisplay.
  902. * rl_complete:                          How Completing Works.
  903. * rl_complete:                          Completion Functions.
  904. * rl_completer_quote_characters:        Completion Variables.
  905. * rl_completer_word_break_characters:   Completion Variables.
  906. * rl_complete_internal:                 Completion Functions.
  907. * rl_completion_entry_function:         Completion Variables.
  908. * rl_completion_entry_function:         How Completing Works.
  909. * rl_completion_query_items:            Completion Variables.
  910. * rl_copy_keymap:                       Keymaps.
  911. * rl_copy_text:                         Modifying Text.
  912. * rl_delete_text:                       Modifying Text.
  913. * rl_discard_keymap:                    Keymaps.
  914. * rl_done:                              Function Writing.
  915. * rl_do_undo:                           Allowing Undoing.
  916. * rl_end:                               Function Writing.
  917. * rl_end_undo_group:                    Allowing Undoing.
  918. * rl_filename_completion_desired:       Completion Variables.
  919. * rl_filename_quoting_desired:          Completion Variables.
  920. * rl_forced_update_display:             Redisplay.
  921. * rl_function_of_keyseq:                Associating Function Names and Bindings.
  922. * rl_generic_bind:                      Binding Keys.
  923. * rl_get_keymap:                        Keymaps.
  924. * rl_get_keymap_by_name:                Keymaps.
  925. * rl_ignore_completion_duplicates:      Completion Variables.
  926. * rl_ignore_some_completions_function:  Completion Variables.
  927. * rl_insert_completions:                Completion Functions.
  928. * rl_insert_text:                       Modifying Text.
  929. * rl_instream:                          Function Writing.
  930. * rl_invoking_keyseqs:                  Associating Function Names and Bindings.
  931. * rl_invoking_keyseqs_in_map:           Associating Function Names and Bindings.
  932. * rl_kill_text:                         Modifying Text.
  933. * rl_line_buffer:                       Function Writing.
  934. * rl_make_bare_keymap:                  Keymaps.
  935. * rl_make_keymap:                       Keymaps.
  936. * rl_mark:                              Function Writing.
  937. * rl_message:                           Redisplay.
  938. * rl_modifying:                         Allowing Undoing.
  939. * rl_named_function:                    Associating Function Names and Bindings.
  940. * rl_on_new_line:                       Redisplay.
  941. * rl_outstream:                         Function Writing.
  942. * rl_parse_and_bind:                    Binding Keys.
  943. * rl_pending_input:                     Function Writing.
  944. * rl_point:                             Function Writing.
  945. * rl_possible_completions:              Completion Functions.
  946. * rl_prompt:                            Function Writing.
  947. * rl_readline_name:                     Function Writing.
  948. * rl_redisplay:                         Redisplay.
  949. * rl_reset_line_state:                  Redisplay.
  950. * rl_reset_terminal:                    Utility Functions.
  951. * rl_set_keymap:                        Keymaps.
  952. * rl_special_prefixes:                  Completion Variables.
  953. * rl_startup_hook:                      Function Writing.
  954. * rl_terminal_name:                     Function Writing.
  955. * rl_unbind_key:                        Binding Keys.
  956. * rl_unbind_key_in_map:                 Binding Keys.
  957. * self-insert (a, b, A, 1, !, ...):     Commands For Text.
  958. * show-all-if-ambiguous:                Readline Init Syntax.
  959. * start-kbd-macro (C-x ():              Keyboard Macros.
  960. * tab-insert (M-TAB):                   Commands For Text.
  961. * tilde-expand (M-~):                   Miscellaneous Commands.
  962. * to_lower:                             Utility Functions.
  963. * to_upper:                             Utility Functions.
  964. * transpose-chars (C-t):                Commands For Text.
  965. * transpose-words (M-t):                Commands For Text.
  966. * undo (C-_, C-x C-u):                  Miscellaneous Commands.
  967. * universal-argument ():                Numeric Arguments.
  968. * unix-line-discard (C-u):              Commands For Killing.
  969. * unix-word-rubout (C-w):               Commands For Killing.
  970. * upcase-word (M-u):                    Commands For Text.
  971. * uppercase_p:                          Utility Functions.
  972. * username_completion_function:         Completion Functions.
  973. * yank (C-y):                           Commands For Killing.
  974. * yank-last-arg (M-., M-_):             Commands For History.
  975. * yank-nth-arg (M-C-y):                 Commands For History.
  976. * yank-pop (M-y):                       Commands For Killing.
  977.  
  978.  
  979.